<?php

$api = app('Dingo\Api\Routing\Router');

$params = [
    'middleware' => [
        'api.throttle',
        'bindings',
        'serializer:array',
    ],
    'limit'      => 60,
    'expires'    => 1,
];

$api->version('v1', $params, function($api) {
    $api->group(['prefix' => 'admin'], function($api) {
        //需要登录的路由
        $api->group(['middleware' => ['api.auth', 'check.permission']], function($api) {
            /**
             * 用户管理
             */
            //禁用和启用用户
            $api->patch('user/{user}/lock', [\App\Http\Controllers\Admin\UserController::class, 'lock'])->name('users.lock');
            //用户管理资源路由
            $api->resource('users', \App\Http\Controllers\Admin\UserController::class, [
                'only' => ['index', 'show'],
            ]);
            /**
             * 分类管理
             */
            //分类禁用和启用
            $api->patch('category/{category}/status', [\App\Http\Controllers\Admin\CategoryController::class, 'status']);
            //分类管理
            $api->resource('category', \App\Http\Controllers\Admin\CategoryController::class, [
                'except' => ['destroy'],
            ]);

            /**
             * 商品管理
             */
            //商品推荐和取消推荐
            $api->patch('goods/{good}/recommend', [\App\Http\Controllers\Admin\GoodsController::class, 'isRecommend']);
            //商品上架和下架
            $api->patch('goods/{good}/on', [\App\Http\Controllers\Admin\GoodsController::class, 'isOn']);
            //商品管理路由
            $api->resource('goods', \App\Http\Controllers\Admin\GoodsController::class, [
                'except' => ['destroy'],
            ]);

            /**
             * 图片上传管理
             */
            $api->post('image', [\App\Http\Controllers\Admin\ImageController::class, 'store']);
            $api->post('image/base64', [\App\Http\Controllers\Admin\ImageController::class, 'storeBase64']);
            $api->delete('image', [\App\Http\Controllers\Admin\ImageController::class, 'destroy']);

            /**
             * 评价管理
             */
            // 评价列表
            $api->get('comment', [\App\Http\Controllers\Admin\CommentController::class, 'index']);
            //评价详情
            $api->get('comment/{comment}', [\App\Http\Controllers\Admin\CommentController::class, 'show']);
            //回复评价
            $api->patch('comment/{comment}/reply', [\App\Http\Controllers\Admin\CommentController::class, 'reply']);

            /**
             * 订单管理
             */
            //订单列表
            $api->get('order', [\App\Http\Controllers\Admin\OrderController::class, 'index']);
            //订单详情
            $api->get('order/{order}', [\App\Http\Controllers\Admin\OrderController::class, 'show']);
            //发货
            $api->patch('order/{order}/post', [\App\Http\Controllers\Admin\OrderController::class, 'post']);

            /**
             * 轮播图管理
             */
            $api->resource('slider', \App\Http\Controllers\Admin\SliderController::class);
            //排序
            $api->patch('slider/{slider}/seq', [\App\Http\Controllers\Admin\SliderController::class, 'seq']);

            /**
             * 菜单管理
             */
            $api->get('menus', [\App\Http\Controllers\Admin\MenuController::class, 'index']);
        });
    });
});

